<?php
	$contextMenu = array();
	
	//makes the context menu resizable
	jQuery::Resizable('context_menu', array('minWidth' => '100'));
	
	echo "<div style = 'padding: 3px 3px 10px 3px; width: 200px; height: 100%; border-right: 0px; border-top: 0px; $display_left_column ' id = 'context_menu' class='ui-widget-content'>";
	
	//generates contextual 2-level menu depending on user roles
	$i = 0;
	$active_sub_module = 0;
	foreach (Menus::$contextual as $key => $value)
	{
		global $object;
		
		//clears the content
		$menuContent = '';
		
		//selects current module
		if ($value['module'] == $this->module)
		{	
		    //if has sub menus
			if (!empty($value['sub']))
			{	
				//lists through all menu elements			
				foreach ($value['sub'] as $sub)
				{
					//do not shows forbidden link in case table access control is turned on
					if ($object->config->use_table_access)
					{
						if (empty($_SESSION['table_accesses'][$sub['table_name']]['access_list']))
						{
						    continue;
						}
					}

					//determines link css class depending on its status (active/not active)
					$processed_server_address = trim($_SERVER['REQUEST_URI'], '?/');
					if (strpos($processed_server_address, '/') !== FALSE)
						$processed_server_address = substr($processed_server_address,0,strpos($processed_server_address, '/'));
						
					if ($processed_server_address == trim($sub['url'], '/'))
					{
					    $link_class = 'context_menu_item_active';
					    $active_sub_module = $i;
					}
					else
					{
					    $link_class = 'context_menu_item';
					}					
					
					//generates the menu item
					$menuContent .= "
                        <div class='$link_class'>
                        	<a href = '{$sub['url']}'>".ucfirst($sub['text'])."</a>
                        </div>
    				";
				}
			}
			
			$menuHeader = ucfirst($value['text']);
			$contextMenu[$menuHeader] = $menuContent;
			$i++;
		}
	}
	
	jQuery::Accordion('contextMenu', $contextMenu, array('collapsible' => 'true', 'active' => $active_sub_module));
	
	echo '</div>';
?>